package cntr.proxies;

import cntr.JGbContainer;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Thanh-Trung Pham.
 */
public class SourceRoleProxy implements InvocationHandler {
    private JGbContainer m_oLocalContainer;

    private List<String> m_oSinkContainerNames = new ArrayList<>(); //the names of containers hosting the deployable entities (component instances or channels) playing the sink role.
    private List<String> m_oSinkDeployableEntityNames = new ArrayList<>(); //the name of the deployable entities (component instances or channels) playing the sink role.

    /**
     * The constructor.
     * @param localContainer the local container (a.k.a the container of the component instance having this sink role)
     */
    public SourceRoleProxy(JGbContainer localContainer) {
        m_oLocalContainer = localContainer;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        m_oLocalContainer.sendMethodInvocationMessages(m_oSinkContainerNames, m_oSinkDeployableEntityNames, method, args);
        return null;
    }

    /**
     * Add a sink container name and a sink deployable entity name.
     * @param sinkContainerName the given sink container name.
     * @param sinkDeployableEntityName the given sink deployable entity name.
     */
    public void addSinkContainerNameAndSinkDeployableEntityName(String sinkContainerName, String sinkDeployableEntityName){
        m_oSinkContainerNames.add(sinkContainerName);
        m_oSinkDeployableEntityNames.add(sinkDeployableEntityName);

    }


}
